//
//  NewClientViewController.m
//  Marketing
//
//  Created by HanenDev on 16/3/2.
//  Copyright © 2016年 Hanen 3G 01. All rights reserved.
//

#import "NewClientViewController.h"
#import "SatusSelectViewController.h"
#import "JudgeNumber.h"
#import "MapClientViewController.h"
#import "ClientsViewController.h"
#import "SVProgressHUD.h"
#import "MyTextView.h"
#import "CardScanViewController.h"
#import "ImageButton.h"

#define STARTX [UIView getWidth:10]
#define InfoCellH 44.0f //每格的高度
#define TitileW 70.0f //每个标题label的宽度
@interface NewClientViewController ()<UITextFieldDelegate,StatusSelectDelegate,MapClientViewControllerDelegate>
{
    NSArray      *_basicArray;
    NSArray      *_contactArray;
    
    UIScrollView * scrollView;
    UITableView  *tableView;
    
    CLLocationCoordinate2D coordinate;
    
    UIView *firstView;
    UIView *secondView;
    UIView *thirdView;
    NSIndexPath   *NowIndexPathLevel;
    NSIndexPath   *NowIndexPathFrom;
    NSIndexPath   *NowIndexPathStatus;
}
//客户信息
@property(nonatomic,strong)UITextField    *companyTF,*addressTF,*levelTF,*fromTF,*statusTF;

@property(nonatomic,strong)ImageButton       *levelBtn,*formBtn,*statusBtn;
@property(nonatomic,strong)ImageButton       *locationBtn;
//联系人信息
@property(nonatomic,strong)UITextField    *nameTF,*phoneTF,*emailTF,*businessTF;
@property(nonatomic,strong)MyTextView     *remarkTF;

@end

@implementation NewClientViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = graySectionColor;
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.hidesBackButton = YES;
    
    self.navigationItem.titleView = [ViewTool getNavigitionTitleLabel:@"新建客户"];
    
    
    self.navigationItem.leftBarButtonItem=[ViewTool getBarButtonItemWithTarget:self WithAction:@selector(goToBack)];
    
    self.navigationItem.rightBarButtonItem = [ViewTool getBarButtonItemWithTarget:self WithString:@"HY_nav_icon_scanning" WithAction:@selector(scanning)];
    _basicArray = @[@"公司",@"地址",@"级别",@"来源",@"状态"];
    _contactArray = @[@"姓名",@"职务",@"电话",@"邮箱",@"备注"];
    
    [self createUI];
    [self addBtn];
    
    //获取数据字典
    [self getDictWith:1];//等级
    [self getDictWith:2];//状态
    [self getDictWith:3];//来源
    
    _levelArray = [NSMutableArray array];
    _statusArray = [NSMutableArray array];
    _fromArray = [NSMutableArray array];
}
#pragma mark------数据字典
- (void)getDictWith:(int)number{
    
    NSNumber *num =[NSNumber numberWithInt:number];
    NSDictionary * dic =@{@"token":TOKEN,@"uid":@(UID),@"type":num };
    [DataTool postWithUrl:GET_DICTIONARY_URL parameters:dic success:^(id data) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSMutableArray *mutArray = [(NSDictionary *)jsonDic objectForKey:@"list"];
        //        NSLog(@"%@opopopopooopooppo",jsonDic);
        if (number == 1) {
            for (int i=0; i<mutArray.count; i++) {
                NSDictionary *dicc = mutArray[i];
                [_levelArray addObject:dicc[@"level"]];
            }
        }else if (number == 2){
            for (int i=0; i<mutArray.count; i++) {
                NSString *level = [mutArray[i] objectForKey:@"level"];
                [_statusArray addObject:level];
            }
        }else if (number == 3){
            for (int i=0; i<mutArray.count; i++) {
                NSString *level1 = [mutArray[i] objectForKey:@"level"];
                [_fromArray addObject:level1];
            }
        }
        //                NSLog(@"%@%@%@",_levelArr,_statusArr,_fromArr);
    } fail:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
}

#pragma mark-----扫描
- (void)scanning
{
    CardScanViewController *cardScanViewController = [[CardScanViewController alloc] init];
    if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
        self.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    }
    cardScanViewController.result = 1;
    [self.navigationController pushViewController:cardScanViewController animated:NO];
}
- (void)createUI{
    
    scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW, KSCreenH - 64-70)];
    scrollView.showsVerticalScrollIndicator=NO;
    scrollView.alwaysBounceVertical = YES;
    [self.view addSubview:scrollView];
    
    
    [self initSectionOne];
    [self initSectionTwo];
    //      [self initSectionThird];
    
}
- (void)initCardDictionary{
    
    NSLog(@"%@",_dictionary);
    
    NSArray *array;
    if (_dictionary.count>0) {
        
        array = [_dictionary objectForKey:@"comp"];
        if (array.count > 0) {
            _companyTF.text = array[0];
        }
        
        array = [_dictionary objectForKey:@"name"];
        if (array.count > 0) {
            _nameTF.text = array[0];
        }
        
        
        array = [_dictionary objectForKey:@"title"];
        if (array.count > 0) {
            _businessTF.text = array[0];
        }
        
        array = [_dictionary objectForKey:@"mobile"];
        if (array.count > 0) {
            _phoneTF.text = array[0];
        }
        
        array = [_dictionary objectForKey:@"email"];
        if (array.count > 0) {
            _emailTF.text = array[0];
        }
        
        array = [_dictionary objectForKey:@"addr"];
        if (array.count > 0) {
            _addressTF.text = array[0];
        }
        
        
    }else{
        
    }
    
}
- (void)initSectionOne{
    CGFloat labelH = InfoCellH;
    CGFloat tfH    = InfoCellH;
    CGFloat tfW    = KSCreenW - 2 * STARTX - 80.0f;
    
    firstView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW, 120.0f)];
    firstView.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:firstView];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCreenW, 40)];
    view.backgroundColor = graySectionColor;
    [firstView addSubview:view];
    
    
    UILabel *basicLabel = [[UILabel alloc]initWithFrame:CGRectMake(STARTX, 20, 200, 20)];
    basicLabel.text = @"客户信息";
    [ViewTool setLableFont12:basicLabel];
    basicLabel.textColor = blackFontColor;
    [view addSubview:basicLabel];
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 40 - 1, KSCreenW , 1)];
    lineView.backgroundColor = grayLineColor;
    [view addSubview:lineView];
    
    for (int i = 0; i<_basicArray.count; i++) {
        UILabel *label = [ViewTool getLabelWith:CGRectMake(STARTX, view.maxY + InfoCellH*i, 80.0f, labelH) WithTitle:_basicArray[i] WithFontSize:13.0f WithTitleColor:lightGrayFontColor WithTextAlignment:NSTextAlignmentLeft];
        [ViewTool setLableFont13:label];
        [firstView addSubview:label];
        
        UIView *line = [ViewTool getLineViewWith:CGRectMake(STARTX, view.maxY +InfoCellH*(i+1) -1 , KSCreenW - STARTX, 1) withBackgroudColor:grayLineColor];
        [firstView addSubview:line];
        
        if (i == _basicArray.count - 1) {
            line.frame = CGRectMake(0, view.maxY +InfoCellH*(i+1) -1 , KSCreenW - 0, 1);
        }
    }
    
    _companyTF = [self addTextFieldWithFrame:CGRectMake(STARTX+ TitileW, view.maxY, tfW, tfH) AndStr:@"请填写公司名称(必填)"];
    [firstView addSubview:_companyTF];
    
    _addressTF = [self addTextFieldWithFrame:CGRectMake(STARTX+ TitileW, _companyTF.maxY, tfW, tfH) AndStr:@"请选择地址(必填)" ];
    _addressTF.enabled = NO;
    [firstView addSubview:_addressTF];
    
    _locationBtn = [[ImageButton alloc]initWithFrame:CGRectMake(STARTX +TitileW, _addressTF.y + InfoCellH / 2.0f  -  40 / 2.0f, KSCreenW - STARTX - TitileW, 40)];
    [_locationBtn addTarget:self action:@selector(clickToLoaction:) forControlEvents:UIControlEventTouchUpInside];
    [_locationBtn setImage:[UIImage imageNamed:@"HY_list_icon_arrow"] forState:UIControlStateNormal];
    [firstView addSubview:_locationBtn];
    
    
    _levelTF = [self addTextFieldWithFrame:CGRectMake(STARTX+ TitileW, _addressTF.maxY , tfW, tfH) AndStr:@"请选择拜访人员级别(必填)"];
    _levelTF.enabled = NO;
    [firstView addSubview:_levelTF];
    
    _levelBtn = [[ImageButton alloc]initWithFrame:CGRectMake(STARTX +TitileW, _levelTF.y + InfoCellH / 2.0f - 40 / 2.0f , KSCreenW -STARTX - TitileW, 40)];
    [_levelBtn addTarget:self action:@selector(clickToSelect:) forControlEvents:UIControlEventTouchUpInside];
    [_levelBtn setImage:[UIImage imageNamed:@"HY_list_icon_arrow"] forState:UIControlStateNormal];
    _levelBtn.tag = 1000;
    [firstView addSubview:_levelBtn];
    
    
    _fromTF = [self addTextFieldWithFrame:CGRectMake(STARTX+ TitileW, _levelTF.maxY , tfW, tfH) AndStr:@"请填写客户来源(必填)"];
    _fromTF.enabled = NO;
    [firstView addSubview:_fromTF];
    
    _formBtn = [[ImageButton alloc]initWithFrame:CGRectMake(_fromTF.x, _fromTF.y + InfoCellH / 2.0f - 40 / 2.0f , KSCreenW - STARTX - TitileW, 40)];
    [_formBtn addTarget:self action:@selector(clickToSelect:) forControlEvents:UIControlEventTouchUpInside];
    [_formBtn setImage:[UIImage imageNamed:@"HY_list_icon_arrow"] forState:UIControlStateNormal];
    _formBtn.tag = 2000;
    [firstView addSubview:_formBtn];
    
    _statusTF = [self addTextFieldWithFrame:CGRectMake(STARTX+ TitileW, _fromTF.maxY , tfW, tfH) AndStr:@"请选择状态(必填)"];
    _statusTF.enabled = NO;
    [firstView addSubview:_statusTF];
    
    _statusBtn = [[ImageButton alloc]initWithFrame:CGRectMake(_statusTF.x, _statusTF.y + InfoCellH / 2.0f - 40 / 2.0f , KSCreenW - STARTX - TitileW, 40)];
    [_statusBtn addTarget:self action:@selector(clickToSelect:) forControlEvents:UIControlEventTouchUpInside];
    [_statusBtn setImage:[UIImage imageNamed:@"HY_list_icon_arrow"] forState:UIControlStateNormal];
    _statusBtn.tag = 3000;
    [firstView addSubview:_statusBtn];
    
    firstView.frame = CGRectMake(0, 0, KSCreenW, _statusTF.maxY);
}
- (void)initSectionTwo{
    CGFloat labelH = InfoCellH;
    CGFloat tfH    = InfoCellH;
    
    CGFloat tfW    = [UIView getWidth:200];
    
    secondView = [[UIView alloc]initWithFrame:CGRectMake(0, firstView.maxY - 1  , KSCreenW, 30)];
    secondView.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:secondView];
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0  , KSCreenW, 40)];
    view.backgroundColor = graySectionColor;
    [secondView addSubview:view];
    
    
    UILabel *basicLabel = [[UILabel alloc]initWithFrame:CGRectMake(STARTX,  20, 200, 20)];
    basicLabel.text = @"联系人信息";
    [ViewTool setLableFont12:basicLabel];
    basicLabel.textColor = blackFontColor;
    [view addSubview:basicLabel];
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 40 - 1, KSCreenW , 1)];
    lineView.backgroundColor = grayLineColor;
    [view addSubview:lineView];
    
    for (int i = 0; i<_contactArray.count; i++) {
        UILabel *label = [ViewTool getLabelWith:CGRectMake(STARTX, view.maxY + InfoCellH*i, KSCreenW, labelH) WithTitle:_contactArray[i] WithFontSize:16.0f WithTitleColor:grayFontColor WithTextAlignment:NSTextAlignmentLeft];
        [ViewTool setLableFont13:label];
        [secondView addSubview:label];
        
        if (i != _contactArray.count - 1) {
            
            UIView *line = [ViewTool getLineViewWith:CGRectMake(STARTX, view.maxY +InfoCellH*(i+1) -1 , KSCreenW - STARTX, 1) withBackgroudColor:grayLineColor];
            [secondView addSubview:line];
        }
    }
    
    _nameTF = [self addTextFieldWithFrame:CGRectMake(STARTX + TitileW, view.maxY , tfW, tfH) AndStr:@"请填写姓名(必填)"];
    [secondView addSubview:_nameTF];
    
    _businessTF = [self addTextFieldWithFrame:CGRectMake(STARTX + TitileW, _nameTF.maxY , tfW, tfH) AndStr:@"请填写职务"];
    [secondView addSubview:_businessTF];
    
    _phoneTF = [self addTextFieldWithFrame:CGRectMake(STARTX + TitileW, _businessTF.maxY, tfW, tfH) AndStr:@"请填写电话(必填)"];
    [secondView addSubview:_phoneTF];
    
    
    _emailTF = [self addTextFieldWithFrame:CGRectMake(STARTX + TitileW, _phoneTF.maxY, tfW, tfH) AndStr:@"请填写邮箱"];
    [secondView addSubview:_emailTF];
    
    
    _remarkTF = [[MyTextView alloc] initWithFrame:CGRectMake(STARTX + TitileW - 2, _emailTF.maxY , KSCreenW - 2 * STARTX - 80.0f, tfH)];
    _remarkTF.placehoder = @"请填写备注";
    _remarkTF.textColor = blackFontColor;
    _remarkTF.font = [ViewTool getFont14];
    _remarkTF.placehoderColor = placeholderGrayFontColor;
    [secondView addSubview:_remarkTF];
    
    
    
    secondView.frame = CGRectMake(0, firstView.maxY, KSCreenW, _remarkTF.maxY);
    
    UIView *l = [[UIView alloc]initWithFrame:CGRectMake(0,  secondView.height - 1, KSCreenW , 1)];
    l.backgroundColor = grayLineColor;
    [secondView addSubview:l];
    
    scrollView.contentSize = CGSizeMake(KSCreenW, secondView.maxY + 20);
}

- (void)addBtn{
    UIView *postView = [ViewTool getLineViewWith:CGRectMake(0, KSCreenH - 70 -64, KSCreenW, 70) withBackgroudColor:[UIColor whiteColor]];
    [self.view addSubview:postView];
    
    UIButton * postBtn = [[UIButton alloc] initWithFrame:CGRectMake(13, 8, postView.width - 20, postView.height - 10)];
    [postBtn setTitle:@"确认提交" forState:UIControlStateNormal];
    [postBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [postBtn addTarget:self action:@selector(referNewClient:) forControlEvents:UIControlEventTouchUpInside];
    [postBtn setBackgroundImage:[UIImage imageNamed:@"HY_btn_red_normal.png"] forState:UIControlStateNormal];
    [postBtn setBackgroundImage:[UIImage imageNamed:@"HY_btn_red_press.png"] forState:UIControlStateSelected];
    [postView addSubview:postBtn];
    
    UIView *line3 = [ViewTool getLineViewWith:CGRectMake(0, 0, KSCreenW, 1) withBackgroudColor:grayLineColor];
    [postView addSubview:line3];
    
}

- (void)clickToSelect:(ImageButton *)btn{
    SatusSelectViewController *vc = [[SatusSelectViewController alloc]init];
    vc.delegate =self;
    vc.num = btn.tag;
   
    switch (btn.tag) {
        case 1000:
        {
            vc.ar = _levelArray;
            vc.itemTitle = @"等级";
            if (_levelTF.text) {
                vc.valuetTitle = _levelTF.text;
            }
            
            if (NowIndexPathLevel) {
                vc.chooseIndexPath = NowIndexPathLevel;//把前面选择的传到后面
            }
            vc.isLevelOrFromOrStatusType = 1;
        }
            break;
        case 2000:
        {
            vc.itemTitle = @"来源";
            vc.ar = _fromArray;
            if (_fromTF.text) {
                vc.valuetTitle = _fromTF.text;
            }
            
            if (NowIndexPathFrom) {
                vc.chooseIndexPath = NowIndexPathFrom;//把前面选择的传到后面
            }
            vc.isLevelOrFromOrStatusType = 2;
        }
            break;
        case 3000:
        {
            vc.itemTitle = @"客户状态";
            vc.ar = _statusArray;
            if (_statusTF.text) {
                vc.valuetTitle = _statusTF.text;
            }
            
            if (NowIndexPathStatus) {
                vc.chooseIndexPath = NowIndexPathStatus;//把前面选择的传到后面
            }
            vc.isLevelOrFromOrStatusType = 3;
        }
            break;
        default:
            break;
    }
    
    [self.navigationController pushViewController:vc animated:NO];
}
#pragma mark --跳转地图
- (void)clickToLoaction:(ImageButton *)btn{
    
    MapClientViewController *mapVC = [[MapClientViewController alloc]init];
    mapVC.result = 1;
    mapVC.delegate = self;
    [self.navigationController pushViewController:mapVC animated:YES];
    
}
#pragma mark --地图代理返回值
- (void)getClickPlaceName:(NSString *)PlaceString withCoordinat2D:(CLLocationCoordinate2D)pt{
    
    _addressTF.text = PlaceString;
    coordinate = pt;
}
- (void)getToAddress:(NSString *)str{
    _addressTF.text = str;
}
- (void)selectStatusWith:(NSString *)string withNum:(NSInteger)count withInt:(int)number withIndexPath:(NSIndexPath *)indexPath withType:(int)type{
    
    if (count == 1000) {
        _levelTF.text = string;
        NowIndexPathLevel = indexPath;
    }else if (count == 2000){
        _fromTF.text = string;
        NowIndexPathFrom = indexPath;
    }else if(count == 3000){
        _statusTF.text = string;
        NowIndexPathStatus = indexPath;
    }
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
-(UITextField *)addTextFieldWithFrame:(CGRect)frame AndStr:(NSString *)placeholder
{
    UITextField *textF=[[UITextField alloc]initWithFrame:frame];
    textF.userInteractionEnabled = YES;
    textF.textColor = blackFontColor;
    textF.placeholder=placeholder;
    textF.delegate = self;
    [textF setValue:placeholderGrayFontColor forKeyPath:@"_placeholderLabel.textColor"];
    [ViewTool setTFPlaceholderFont14:textF];
    return textF;
}
- (void)goToBack{
    
    CATransition* transition = [CATransition animation];
    transition.type = kCATransitionMoveIn;//可更改为其他方式
    transition.subtype = kCATransitionFromBottom;//可更改为其他方式
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    
    [self.navigationController popViewControllerAnimated:NO];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.tabBarController.hidesBottomBarWhenPushed = NO;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear: animated];
    self.tabBarController.hidesBottomBarWhenPushed = YES;
    
    if (_dictionary.count > 0) {
        [self initCardDictionary];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark ------- 提交

- (void)referNewClient:(UIButton *)btn{
    if (_companyTF.text == nil | [_companyTF.text length] == 0 ){
        [self.view makeToast:@"请添加公司"];
        return;
    }else if (_levelTF.text == nil | [_levelTF.text length] == 0 ){
        [self.view makeToast:@"请选择级别"];
        return;
    }else if (_fromTF.text == nil | [_fromTF.text length] == 0 ){
        [self.view makeToast:@"请选择来源"];
        return;
    }else if (_statusTF.text == nil | [_statusTF.text length] == 0 ){
        [self.view makeToast:@"请选择状态"];
        return;
    }else if (_nameTF.text == nil | [_nameTF.text length] == 0 ){
        [self.view makeToast:@"请填写姓名"];
        return;
    }else if (_phoneTF.text == nil | [_phoneTF.text length] == 0 ){
        [self.view makeToast:@"请填写电话"];
        return;
    }else if (_addressTF.text == nil | [_addressTF.text length] == 0 ){
        [self.view makeToast:@"请填写地址"];
        return;
    }else if (![JudgeNumber boolenPhone:_phoneTF.text]){
        [self.view makeToast:@"请输入正确的手机号"];
        return;
    }
    
    [self getNewClientDetail];
    
}

- (void)getNewClientDetail{
    
    int a1;
    int b1;
    int c1;
    
    a1 = (int)[_levelArray indexOfObject:_levelTF.text] + 1;
    b1 = (int)[_fromArray indexOfObject:_fromTF.text] + 1;
    c1 = (int)[_statusArray indexOfObject:_statusTF.text] + 1;
    
    NSLog(@"%d%d%d",a1,b1,c1);
    NSNumber *levelNum =[NSNumber numberWithInt:a1];
    NSNumber *fromNum =[NSNumber numberWithInt:b1];
    NSNumber *statusNum =[NSNumber numberWithInt:c1];
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithDictionary:@{@"token":TOKEN,@"uid":@(UID),@"company":_companyTF.text,@"level":levelNum,@"source":fromNum,@"status":statusNum,@"address":_addressTF.text}];
    
    NSString *lat = [NSString stringWithFormat:@"%.6f",coordinate.latitude];
    NSString *lon = [NSString stringWithFormat:@"%.6f",coordinate.longitude];
    
    if (coordinate.longitude && coordinate.latitude) {
        [dic setObject:lon forKey:@"lon"];
        [dic setObject:lat forKey:@"lat"];
    }
    NSLog(@"%@   dic++++++++  %@------",dic,ADD_CLIENT_URL);
    
    [DataTool postWithUrl:ADD_CLIENT_URL parameters:dic success:^(id data) {
        NSDictionary *jsonDic = [DataTool changeType:[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]];
        NSLog(@"%@++++++++",jsonDic);
        int code = [jsonDic[@"code"]intValue];
        if (code == 100) {
            [self addpersonsssWith:[jsonDic[@"cid"] intValue]];//这里 返回 新增客户的id
        }
    } fail:^(NSError *error) {
        NSLog(@"%@",error);
        [self.view makeToast:error.localizedDescription];
    }];
    
    
}
- (void)addpersonsssWith:(int)clientId
{
    NSDictionary * dic =@{@"token":TOKEN,@"uid":@(UID),@"cid":@(clientId),@"name":_nameTF.text,@"position":_businessTF.text,@"phone":_phoneTF.text,@"email":_emailTF.text,@"remark":_remarkTF.text};
    NSMutableDictionary *paramDict = [DataTool changeType:dic];
    [DataTool postWithUrl:ADD_NEW_TEL_PERSON parameters:paramDict success:^(id data) {
        id backData = CRMJsonParserWithData(data);
        NSLog(@"添加联系人 返回数据%@",backData);
        if ([backData[@"code"] intValue] == 100) {
            [SVProgressHUD showSuccessWithStatus:@"新建成功"];
            
            [self performSelector:@selector(goToBack) withObject:nil afterDelay:0.5];
        }
    } fail:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
        [self.view makeToast:error.localizedDescription];
    }];
    
}
-(UITextField *)addTextFieldWithFrame:(CGRect)frame AndStr:(NSString *)placeholder WithTrue:(BOOL)ture{
    
    UITextField *textF=[[UITextField alloc]initWithFrame:frame];
    textF.userInteractionEnabled = ture;
    textF.textColor = blackFontColor;
    textF.placeholder=placeholder;
    textF.delegate = self;
    [textF setValue:placeholderGrayFontColor forKeyPath:@"_placeholderLabel.textColor"];
    [ViewTool setTFPlaceholderFont14:textF];
    return textF;
}
@end
